package nl.unimaas.group11.project1_3.algo;

public class Greedy {

	private double volumeA;
	private double volumeB;
	private double volumeC;
	private double ratioA;
	private double ratioB;
	private double ratioC;
	private int position;
	public Bruteforce greedy;
	public int[][][] solution;
	

	public Greedy(int boxAValue, int boxBValue, int boxCValue, int containerX, int containerY, int containerZ) {
		greedy = new Bruteforce(boxAValue, boxBValue, boxCValue, containerX, containerY, containerZ);
		volumeA = 16;
		volumeB = 24;
		volumeC = 27;

		ratioA = boxAValue / volumeA;

		ratioB = boxBValue / volumeB;

		ratioC = boxCValue / volumeC;

		greedy.boxes = boxesOrder(greedy.boxes);
		
		
		
		

	}
	public void start(int seconds){
		greedy.start(false, true, seconds);
		solution = greedy.bestSolution;
	}
	
	

	private int[][] boxesOrder(int[][] boxes) {
		int[][] boxesOptimal = new int[boxes.length][boxes[0].length];

		int[][] boxesA = { { 1, 2, 4, 2 }, { 2, 2, 2, 4 }, { 3, 4, 2, 2 } };
		int[][] boxesB = { { 4, 4, 3, 2 }, { 5, 4, 2, 3 }, { 6, 2, 4, 3 }, { 7, 3, 4, 2 }, { 8, 2, 3, 4 }, { 9, 3, 2, 4 } };
		int[][] boxesC = { { 10, 3, 3, 3 } };

		if (ratioA >= ratioB) {
			if (ratioB >= ratioC) {
				// a,b,c
				boxesOptimal = boxArrayFill(boxesA,boxesB,boxesC,boxesOptimal);
			} else if (ratioA >= ratioC) {
				// a,c,b
				boxesOptimal = boxArrayFill(boxesA,boxesC,boxesB,boxesOptimal);
			} else {
				// c,a,b
				boxesOptimal = boxArrayFill(boxesC,boxesA,boxesB,boxesOptimal);
			}
		} else if (ratioB >= ratioC) {
			if (ratioA >= ratioC) {
				// b,a,c
				boxesOptimal = boxArrayFill(boxesB,boxesA,boxesC,boxesOptimal);
			} else {
				// b,c,a
				boxesOptimal = boxArrayFill(boxesB,boxesC,boxesA,boxesOptimal);
			}
		} else {
			// c,b,a
			boxesOptimal = boxArrayFill(boxesC,boxesB,boxesA,boxesOptimal);
		}

		return boxesOptimal;
	}

	private int[][] boxArrayFill(int[][] first, int[][] second, int[][] third, int[][] boxes) {


		for (int x = 0; x < first.length; x++) {
			for (int y = 0; y < 4; y++) {
				boxes[x][y]= first[x][y];

			}
		}
		position+=first.length;

		for (int x = 0; x < second.length; x++) {
			for (int y = 0; y < 4; y++) {
				boxes[x+position][y]= second[x][y];
			}
			
		}
		position+=second.length;

		for (int x= 0; x < third.length; x++) {
			for (int y = 0; y < 4; y++) {
				boxes[x+position][y]= third[x][y];
			}
		}
		
		return boxes;
	}
}
